//获取数据的动作
//引入常量
import { GET_MIAOSHA_DATA, GET_SWIPER_DATA, GET_TUIJIAN_DATA, GET_ITEMOBJ_DATA, GET_SWIPERARR_DATA, GET_JIESHAOLIST_DATA } from '../content';

import axios from 'axios';
//获取首页数据
export function fetchMainData() {
    return dispatch => {
        axios.post("https://srv.hotkidceo.com/appapi/api/root-ceo-content/hpPageConfigure/pageList", { "channelId": null, "memberKey": "" }
        ).then(res => {
            // console.log("action12-", res);
            //调用 纯函数
            dispatch({
                type: GET_TUIJIAN_DATA, data: res.data.data[10].configureAttributeList
            });
            dispatch({
                type: GET_MIAOSHA_DATA, data: res.data.data[5]
            });
            dispatch({
                type: GET_SWIPER_DATA, data: res.data.data[1].configureAttribute
            });

        })
    }
}

//获取内容页数据
export function fetchItemData(ptKey) {
    return dispatch => {
        axios.post('https://srv.hotkidceo.com/appapi/root-ceo-commodity/commodityApi/commodityDetail', { "ptKey": ptKey, "memberKey": "", "isWholeSale": 0, "channelId": null }).then(res => {
            console.log("action12-", res);
            //调用 纯函数
            dispatch({
                type: GET_ITEMOBJ_DATA, data: res.data.data,
            });
            dispatch({
                type: GET_SWIPERARR_DATA, data: res.data.data.templateInfo.bannerImages.split(','),
            });
            dispatch({
                type: GET_JIESHAOLIST_DATA, data: res.data.data.templateInfo.detailImages.split(',')
            });
        })
    }
}
